package cn.tedu.project.oa.attendanceRule.controller;

import cn.tedu.project.oa.attendanceRule.pojo.entity.LeaveType;
import cn.tedu.project.oa.attendanceRule.service.ILeaveTypeService;
import cn.tedu.project.oa.base.response.JsonResult;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("oa/attendance/leaveType")
@Api(tags = "08.请假规则")
public class LeaveTypeController {
    @Autowired
    private ILeaveTypeService leaveTypeService;

    /**
     * 查询请假类型列表
     */
    @GetMapping("/list")
    public JsonResult list(LeaveType leaveType)
    {
        List<LeaveType> list = leaveTypeService.selectLeaveTypeList(leaveType);
        return JsonResult.ok(list);
    }

//    /**
//     * 导出请假类型列表
//     */
//    @Log(title = "请假类型", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, LeaveType leaveType)
//    {
//        List<LeaveType> list = leaveTypeService.selectLeaveTypeList(leaveType);
//        ExcelUtil<LeaveType> util = new ExcelUtil<LeaveType>(LeaveType.class);
//        util.exportExcel(response, list, "请假类型数据");
//    }

    /**
     * 获取请假类型详细信息
     */
    @GetMapping(value = "/{id}")
    public JsonResult getInfo(@PathVariable("id") Long id)
    {
        return JsonResult.ok(leaveTypeService.selectLeaveTypeById(id));
    }

    /**
     * 新增请假类型
     */
    @PostMapping
    public JsonResult add(LeaveType leaveType)
    {
        return JsonResult.ok(leaveTypeService.insertLeaveType(leaveType));
    }

    /**
     * 修改请假类型
     */
    @PutMapping
    public JsonResult edit(LeaveType leaveType)
    {
        return JsonResult.ok(leaveTypeService.updateLeaveType(leaveType));
    }

    /**
     * 删除请假类型
     */
    @DeleteMapping("/{ids}")
    public JsonResult remove(@PathVariable Long[] ids)
    {
        return JsonResult.ok(leaveTypeService.deleteLeaveTypeByIds(ids));
    }
}
